A union of 3 values.
- T1
- The first value type.
- T2
- The second value type.
- T3
- The third value type.
An Either is an immutable, strongly typed union of variously typed values with each value lacking an otherwise meaningful name aside from its position, which is not exposed. It stores only one (non-null) value from a set of types (as determined by the type parameter list).
The value held by a Cadenza.Either<T1, T2, T3> instance can be converted into a value by using the Either<T1, T2, T3>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>) method. Fold takes a list of delegates to perform the conversion; the delegate used to perform the conversion is based upon the internal position of the value stored.
Either instances are created through one of the following creation methods:
- Either<T1, T2, T3>.A(`0)
- Either<T1, T2, T3>.op_Implicit(`0)
- Either<T1, T2, T3>.B(`1)
- Either<T1, T2, T3>.op_Implicit(`1)
- Either<T1, T2, T3>.C(`2)
- Either<T1, T2, T3>.op_Implicit(`2)
C# Example var a = Either<double, string>.A (Math.PI); // value stored in 1st position int r = a.Fold ( v => (int) v, // 1st position converter v => v.Length); // 2nd position converter Console.WriteLine (r); // prints 3
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
See Also: Inherited members from object.
⊟ Public Methods
staticA (T1) : Either<T1, T2, T3> Creates a Cadenza.Either<T1, T2, T3> instance which holds a T1 value. staticB (T2) : Either<T1, T2, T3> Creates a Cadenza.Either<T1, T2, T3> instance which holds a T2 value. staticC (T3) : Either<T1, T2, T3> Creates a Cadenza.Either<T1, T2, T3> instance which holds a T3 value. abstractEquals (Either<T1, T2, T3>) : bool Determines whether the current instance and the specified Cadenza.Either<T1, T2, T3> have the same value. abstractEquals (object) : bool Determines whether the current instance and the specified object have the same value. abstractFold<TResult> (Func<T1, TResult>, Func<T2, TResult>, Func<T3, TResult>) : TResult Converts a Cadenza.Either<T1, T2, T3> into a TResult value. abstractGetHashCode () : int Generates a hash code for the current instance.⊟ Public Operators
staticConversion to Cadenza.Either<T1,T2,T3> (Implicit) Creates a Cadenza.Either<T1, T2, T3> instance which holds a T1 value. staticConversion to Cadenza.Either<T1,T2,T3> (Implicit) Creates a Cadenza.Either<T1, T2, T3> instance which holds a T2 value. staticConversion to Cadenza.Either<T1,T2,T3> (Implicit) Creates a Cadenza.Either<T1, T2, T3> instance which holds a T3 value. ⊟ Extension Methods
staticJust<T> (this T) : Maybe<T> Create a new Cadenza.Maybe<T> instance initialized to a specified value. The returned value will not be Maybe<T>.Nothing. staticMatch<TSource,TResult> (this TSource, params Func<TSource, Maybe<TResult>>[]) : TResult Converts the TSource instance self into a TResult. staticToMaybe<T> (this T) : Maybe<T> Create a new Cadenza.Maybe<T> instance initialized to a specified value. The returned value may be Maybe<T>.Nothing. staticTraverseBreadthFirst<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<TResult> Traverse a tree in a breadth-first fashion, converting each encountered node. staticTraverseBreadthFirstWithParent<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<KeyValuePair<TSource, TResult>> Traverse a tree in a breadth-first fashion, converting each encountered node. staticTraverseDepthFirst<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<TResult> Traverse a tree in a depth-first fashion, converting each encountered node. staticTraverseDepthFirstWithParent<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<KeyValuePair<TSource, TResult>> Traverse a tree in a depth-first fashion, converting each encountered node. staticWith<TSource,TResult> (this TSource, Func<TSource, TResult>) : TResult Supports chaining otherwise temporary values.
⊟ A Method
Creates a Cadenza.Either<T1, T2, T3> instance which holds a T1 value.
public static Either<T1, T2, T3> A (T1 value)⊟ Parameters
- value
- A T1 containing the value to provide to the first Either<T1, T2, T3>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>) delegate.
⊟ Returns
A Cadenza.Either<T1, T2, T3> instance which holds a holds a T1 value.⊟ Exceptions
Type Reason ArgumentNullException if value is null. ⊟ Remarks
When Either<T1, T2, T3>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>) is invoked, the returned Cadenza.Either<T1, T2, T3> instance will invoke the first delegate for conversions.⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ B Method
Creates a Cadenza.Either<T1, T2, T3> instance which holds a T2 value.
public static Either<T1, T2, T3> B (T2 value)⊟ Parameters
- value
- A T2 containing the value to provide to the second Either<T1, T2, T3>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>) delegate.
⊟ Returns
A Cadenza.Either<T1, T2, T3> instance which holds a holds a T2 value.⊟ Exceptions
Type Reason ArgumentNullException if value is null. ⊟ Remarks
When Either<T1, T2, T3>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>) is invoked, the returned Cadenza.Either<T1, T2, T3> instance will invoke the second delegate for conversions.⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ C Method
Creates a Cadenza.Either<T1, T2, T3> instance which holds a T3 value.
public static Either<T1, T2, T3> C (T3 value)⊟ Parameters
- value
- A T3 containing the value to provide to the third Either<T1, T2, T3>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>) delegate.
⊟ Returns
A Cadenza.Either<T1, T2, T3> instance which holds a holds a T3 value.⊟ Exceptions
Type Reason ArgumentNullException if value is null. ⊟ Remarks
When Either<T1, T2, T3>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>) is invoked, the returned Cadenza.Either<T1, T2, T3> instance will invoke the third delegate for conversions.⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Equals Method
Determines whether the current instance and the specified Cadenza.Either<T1, T2, T3> have the same value.
public abstract bool Equals (Either<T1, T2, T3> obj)⊟ Parameters
- obj
- A Cadenza.Either<T1, T2, T3>to compare this instance against.
⊟ Returns
true if each member of obj and the current instance have the same value (according to object.Equals(object)); otherwise false is returned.⊟ Remarks
This method checks for value equality (object.Equals(object)), as defined by each value type.⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Equals Method
Determines whether the current instance and the specified object have the same value.
⊟ Parameters
- obj
- A object to compare this instance against.
⊟ Returns
true if obj is a Cadenza.Either<T1, T2, T3> and each member of obj and the current instance have the same value (according to object.Equals(object)); otherwise false is returned.⊟ Remarks
This method checks for value equality (object.Equals(object)), as defined by each value type.
Note: This method overrides object.Equals(object).⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Fold<TResult> Generic Method
Converts a Cadenza.Either<T1, T2, T3> into a TResult value.
public abstract TResult Fold<TResult> (Func<T1, TResult> a, Func<T2, TResult> b, Func<T3, TResult> c)⊟ Type Parameters
- TResult
- The type to convert the Cadenza.Either<T1, T2, T3> to.
⊟ Parameters
- a
- A Func<T1, TResult> used if the Cadenza.Either<T1, T2, T3> stores a T1 value into a TResult value.
- b
- A Func<T2, TResult> used if the Cadenza.Either<T1, T2, T3> stores a T2 value into a TResult value.
- c
- A Func<T3, TResult> used if the Cadenza.Either<T1, T2, T3> stores a T3 value into a TResult value.
⊟ Returns
A TResult as generated by one of the conversion delegate parameters.⊟ Exceptions
Type Reason ArgumentNullException a is null.
-or-
b is null.
-or-
c is null.
⊟ Remarks
Converts a Cadenza.Either<T1, T2, T3> into a TResult by invoking one of the provided delegate parameters.
The parameter which is invoked is predicated upon the internal position of the value held. For example, if the internal value is in the first position (i.e. Either<T1, T2, T3>.A(`0) was used to create the Cadenza.Either<T1, T2, T3> instance), then a (the first delegate parameter) will be invoked to convert the T1 into a TResult.
⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ GetHashCode Method
Generates a hash code for the current instance.
public abstract int GetHashCode ()⊟ Returns
A int containing the hash code for this instance.⊟ Remarks
Note: This method overrides object.GetHashCode.⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Conversion Method
Creates a Cadenza.Either<T1, T2, T3> instance which holds a T1 value.
public static implicit operator Either<T1, T2, T3> (T1 value)⊟ See Also
⊟ Parameters
- value
- A T1 containing the value to store.
⊟ Returns
A Cadenza.Either<T1, T2, T3> instance which holds a T1 value.⊟ Exceptions
Type Reason ArgumentNullException if value is null. ⊟ Remarks
This conversion operator is provided to make Cadenza.Either<T1, T2, T3> instance creation easier:
C# Example Either<int, double> value = 42.0; // value stored in 2nd position⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Conversion Method
Creates a Cadenza.Either<T1, T2, T3> instance which holds a T2 value.
public static implicit operator Either<T1, T2, T3> (T2 value)⊟ See Also
⊟ Parameters
- value
- A T2 containing the value to store.
⊟ Returns
A Cadenza.Either<T1, T2, T3> instance which holds a T2 value.⊟ Exceptions
Type Reason ArgumentNullException if value is null. ⊟ Remarks
This conversion operator is provided to make Cadenza.Either<T1, T2, T3> instance creation easier:
C# Example Either<int, double> value = 42.0; // value stored in 2nd position⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Conversion Method
Creates a Cadenza.Either<T1, T2, T3> instance which holds a T3 value.
public static implicit operator Either<T1, T2, T3> (T3 value)⊟ See Also
⊟ Parameters
- value
- A T3 containing the value to store.
⊟ Returns
A Cadenza.Either<T1, T2, T3> instance which holds a T3 value.⊟ Exceptions
Type Reason ArgumentNullException if value is null. ⊟ Remarks
This conversion operator is provided to make Cadenza.Either<T1, T2, T3> instance creation easier:
C# Example Either<int, double> value = 42.0; // value stored in 2nd position⊟ Requirements
Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0